/**
 * Created by jimshi0912 on 15/11/2.
 */
(function () {
    angular.module('my-tabs.directives')
        .directive('headerShrink', headerShrink);

    function headerShrink() {
        return {
            restrict: 'A',
            link: function ($scope, $element, $attr) {
                var resizeFactor, scrollFactor, blurFactor;
                var shrinks = document.querySelectorAll('.shrink');

                $scope.$on('contentScroll.scroll', function (event, scrollView) {
                    var shrink, i;

                    if (scrollView.__scrollTop >= 0) {
                        scrollFactor = scrollView.__scrollTop / 2;
                        for (i = 0; i < shrinks.length; i++) {
                            shrink = shrinks[i];
                            shrink.style[ionic.CSS.TRANSFORM] = 'translate3d(0, ' + scrollFactor + 'px, 0)';
                        }
                    } else {
                        resizeFactor = -scrollView.__scrollTop / 100 + 0.99;
                        //blurFactor = -scrollView.__scrollTop / 10;

                        for (i = 0; i < shrinks.length; i++) {
                            shrink = shrinks[i];
                            shrink.style[ionic.CSS.TRANSFORM] = 'scale(' + resizeFactor + ',' + resizeFactor + ') ';
                        }
                        //header.style.webkitFilter = 'blur(' + blurFactor + 'px)';
                    }
                })
            }
        }
    };
})();
